package com.team.util;


import com.team.constant.CommonConstant;
import lombok.Data;

import java.util.Collection;

/**
 * @author Administrator
 * @version 1.0
 * @date 2021/12/20 15:05
 * @Description: 统一分页实体类
 */
@Data
public class PageSupport<T> {

    /**
     *  页码
     */
    private Integer currPageNo = CommonConstant.UNIFY_RETURN_INIT_PAGE_NO;
    /**
     * 查询条数-每页展示条数
     */
    private Integer pageSize = CommonConstant.UNIFY_RETURN_INIT_PAGE_SIZE;
    /**
     * 总条数
     */
    private Integer totalCount;
    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 当前分页数据
     */
    private Collection<T> data;



    /**
     * 当确定总条数时，可以根据页面容量确定总页数
     */
    public void setTotalCount(Integer totalCount) {
        if (totalCount>0){
            this.totalCount=totalCount;
            this.totalPage=this.totalCount%this.pageSize ==0 ?
                    this.totalCount/this.pageSize
                    : this.totalCount/this.pageSize+1;
        }
    }
}
